import tkinter as tk
import time
from tkinter import messagebox
import re
from tkinter import *

root_window=tk.Tk()
root_window.iconbitmap("D:\毕设实习\logo.ico")  #图标
root_window.geometry('400x300')  #大小比例

# root_window.title('yolo')  #标题
# print("电脑的分辨率是%dx%d"%(root_window.winfo_screenwidth(),root_window.winfo_screenheight()))  #获取电脑屏幕大小
# root_window.update()  #刷新屏幕
# print("窗口的分辨率是%dx%d"%(root_window.winfo_width(),root_window.winfo_height()))
# root_window.config(background="#6fb765")  #背景颜色
# root_window.attributes('-topmost',True)  #设置窗口处于顶层
# root_window.attributes('-alpha',1)  #设置窗口的透明度
# root_window.maxsize(600,600)  #设置窗口被允许最大调整的范围
# root_window.minsize(50,50)  ##设置窗口被允许最小调整的范围
# #root_window["background"]="#83E5F1"  #背景颜色
# text=tk.Label(root_window,text="欢迎您",bg="white",fg="black",font=('Times',20,'bold italic'))  #添加文本设置字体前景色背景色字体类型大小
# text.pack()  #放置文本
# button=tk.Button(root_window,text="关闭",command=root_window.quit)  #添加按钮以及文本，并通过command参数设置关闭窗口的功能
# button.pack(side="bottom")  #放置窗口
# def callback():
#     print("执行回调函数","YOLO欢迎您")
# button=tk.Button(root_window,text="执行",command=callback)  
# button.pack()  


# root_window.title('时钟') 
# def gettime():
#     dstr.set(time.strftime("%H:%M:%S"))  #获取当前时间
#     root_window.after(1000,gettime)  #每隔1s调用一次函数获取时间
# dstr=tk.StringVar()  #生成动态字符串
# lb=tk.Label(root_window,textvariable=dstr,fg='green',font=("微软雅黑",85))  #利用textvariable来实现文本变化
# lb.pack()
# gettime()  #调用生成时间函数


# root_window.title('Label') 
# label=tk.Label(root_window,text="xxxxx",font=('宋体',20,'bold italic'),bg="#7CCD7C",
#                width=30,height=5,  #设置标签内容区大小
#                padx=10,pady=15,borderwidth=10,relief='sunken')  #设置填充区距离、边框宽度和其样式（凹陷式）
# label.pack()


# root_window.title('Button') 
# def click_button():
#     messagebox.showinfo(title='温馨提示',message='xxxxxx')
# button=tk.Button(root_window,text='点击前往',bg='#7CCD7C',width=20,height=5,command=click_button).pack()


# root_window.title('Entry') 
# def checkaccount():
#     if not e1.get().isdigit():
#         messagebox.showinfo("输入不正确","账号必须为数字")
#         e1.delete(0,tk.END)
#         return False
#     return True

# def checkpassword():
#     if len(e2.get())<8:
#         messagebox.showinfo("输入不正确","密码长度必须大于等于8")
#         e2.delete(0,tk.END)
#         return False  
#     has_upper = re.search(r'[A-Z]', e2.get()) is not None
#     has_lower = re.search(r'[a-z]', e2.get()) is not None
#     has_special = re.search(r'[!@#$%^&*(),.?":{}|<>]', e2.get()) is not None
#     if not (has_upper and has_lower and has_special):
#         messagebox.showinfo("输入不正确", "密码必须包含大小写字母和特殊符号")
#         e2.delete(0, tk.END)
#         return False
#     return True

# tk.Label(root_window,text="账号：").grid(row=0)
# tk.Label(root_window,text="密码：").grid(row=1)

# # e1=tk.Entry(root_window)
# # e2=tk.Entry(root_window,show='*')
# # e1.grid(row=0,column=1,padx=10,pady=5)
# # e2.grid(row=1,column=1,padx=10,pady=5)
# def login():
#    if checkaccount() and checkpassword():
#        messagebox.showinfo('欢迎！')

# tk.Button(root_window,text="登录",width=10,command=login).grid(row=3,column=0,sticky="w",padx=10,pady=5)
# tk.Button(root_window,text="退出",width=10,command=root_window.quit).grid(row=3,column=1,sticky="e",padx=10,pady=5)

# Dy_String1=tk.StringVar()
# Dy_String2=tk.StringVar()
# e1=tk.Entry(root_window,textvariable=Dy_String1,validate="focusout",validatecommand=checkaccount)
# e2=tk.Entry(root_window,show='*',textvariable=Dy_String2,validate="focusout",validatecommand=checkpassword)
# e1.grid(row=0,column=1,padx=10,pady=5)
# e2.grid(row=1,column=1,padx=10,pady=5)


# root_window.title('Spinbox')
# #w=tk.Spinbox(root_window,from_=0,to=20,increment=2,width=15,bg='#9BCD9B')
# w=tk.Spinbox(root_window,values=('甲','乙','丙','丁'))
# w.pack() 


# root_window.title('Text')
# text=Text(root_window,width=50,height=10,undo=True,autoseparators=False)
# #text.pack()
# text.grid()
# text.insert(INSERT,'xxxxxxxx')
# def backout():
#     text.edit_undo()
# def regain():
#     text.edit_redo()
# Button(root_window,text="撤销",command=backout).grid(row=3,column=0,sticky="w",padx=10,pady=5)
# Button(root_window,text="恢复",command=regain).grid(row=3,column=0,sticky="e",padx=10,pady=5)


# root_window.title('Menu')
# def menuCommand():
#     messagebox.showinfo("主菜单栏","你正在使用主菜单栏")
# main_menu=Menu(root_window)
# main_menu.add_command(label="文件",command=menuCommand)
# main_menu.add_command(label="编辑",command=menuCommand)
# main_menu.add_command(label="格式",command=menuCommand)
# main_menu.add_command(label="查看",command=menuCommand)
# main_menu.add_command(label="帮助",command=menuCommand)
# root_window.config(menu=main_menu)

# def func():
#     print('弹出了菜单')
# def func1(a):
#     print('弹出了菜单')
# menu=Menu(root_window,tearoff=False)
# menu.add_command(label="新建",command=func,accelerator="Ctrl+N")
# menu.add_command(label="复制",command=func,accelerator="Ctrl+C")
# menu.add_command(label="粘贴",command=func,accelerator="Ctrl+V")
# menu.add_command(label="剪切",command=func,accelerator="Ctrl+X")
# def command(event):
#     menu.post(event.x_root,event.y_root)
# root_window.bind("<Button-3>",command)
# root_window.bind("<Control-n>",func1)
# root_window.bind("<Control-N>",func1)
# root_window.bind("<Control-c>",func1)
# root_window.bind("<Control-C>",func1)
# root_window.bind("<Control-v>",func1)
# root_window.bind("<Control-V>",func1)
# root_window.bind("<Control-x>",func1)
# root_window.bind("<Control-X>",func1)


# root_window.title('pack()布局')
# frame1=tk.Frame(root_window)
# frame1.pack()
# frame_left=tk.Frame(frame1)
# tk.Label(frame_left,text='左侧标签1',bg='green',width=10,height=5).grid(row=0,column=0)
# tk.Label(frame_left,text='左侧标签2',bg='blue',width=10,height=5).grid(row=1,column=1)
# frame_left.pack(side=tk.LEFT)

# frame_right=tk.Frame(frame1)
# tk.Label(frame_right,text='右侧标签1',bg='gray',width=10,height=5).grid(row=0,column=1)
# tk.Label(frame_right,text='右侧标签2',bg='pink',width=10,height=5).grid(row=1,column=0)
# tk.Label(frame_right,text='右侧标签3',bg='purple',width=10,height=5).grid(row=1,column=1)
# frame_right.pack(side=tk.RIGHT)


root_window.title('grid()布局')
for i in range(20):
    for j in range(20):
        Button(root_window,text="("+str(i)+","+str(j)+")",bg='#D1EEEE',width=3).grid(row=i,column=j)
Label(root_window,text="XX",fg='blue',font=('楷体',12,'bold')).grid(row=8,column=21)

root_window.mainloop()  #进入主循环，显示主窗口e